package jp.sourceforge.talisman.mds.cluster;

/*
 * $Id: NonHierarchicalClusteringMethod.java,v 1.1 2009/09/12 05:06:01 weiwei Exp $
 */

import jp.sourceforge.talisman.mds.Item;

/**
 * 
 * @author Haruaki Tamada
 * @version $Revision: 1.1 $ 
 */
public abstract class NonHierarchicalClusteringMethod extends AbstractClusteringMethod{
    public NonHierarchicalClusteringMethod(ClusteringParameter param){
        super(param);
    }

    @Override
    protected abstract Cluster[] doClustering(Item[] items, ClusteringParameter param);

    protected Cluster[] initClusters(Item[] items, NonHierarchicalClusteringParameter param){
        Cluster[] clusters = new Cluster[param.getNumberOfCluster()];
        // initial clustering
        for(int i = 0; i < items.length; i++){
            int index = i % clusters.length;
            if(clusters[index] == null){
                clusters[index] = new Cluster();
                clusters[index].setName("" + index);
            }
            clusters[i % clusters.length].addItem(items[i]);
        }
        return clusters;
    }
}
